package homework.api.day01;

public class StringApiDemo {
    public static void main(String[] args) {
        String str = "    ashjkds 捱三顶五群  ";
        //获取长度
        System.out.println(str.length());
        //去除前后空白
        str = str.trim();
        System.out.println(str);
        //英文大小写转换
        str = str.toUpperCase();
        System.out.println(str);
        str = str.toLowerCase();
        System.out.println(str);
        //判断字符串是否以特定字符开始，结束
        boolean f1 = str.startsWith("sh");
        boolean f2 = str.endsWith("五群");
        System.out.println(f1);
        System.out.println(f2);
        //根据下标获取字符
        char c = str.charAt(6);
        System.out.println(c);
        //char c1 = str.charAt(100);
        //System.out.println(c1);

        //根据字符串获取下标
        int index1 = str.indexOf("s");
        System.out.println(index1);
        int index2 = str.lastIndexOf("s");
        System.out.println(index2);
        int index3 = str.indexOf("soo");
        System.out.println(index3);

        //截取当前字符串中指定范围的字符串(含头不含尾-----包含start不包含end)
        String str1 = str.substring(2,4);
        System.out.println(str1);
        String str2 = str.substring(2);
        System.out.println(str2);

        //将其他类型转换为String
        //String s = 1+"";//效率低
        String s1 = String.valueOf(1);

    }
}
